<template>
    <div>
        <s-search-bar>
            <el-form :model="config" label-width="80px">
                <el-form-item prop="configName" label="参数名">
                    <el-input v-model="config.configName"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button @click="query" icon="el-icon-search" type="primary">查询</el-button>

                    <el-button @click="addSysConfig" icon="el-icon-add" type="primary">新增</el-button>
                </el-form-item>
            </el-form>
        </s-search-bar>
        <basic-table :tableLoading="tableLoading" :tableData="tableData" :tableOption="tableOption" :tablePage="tablePage" @table-search="query">
            <template slot="operation" slot-scope="scope" >
                <el-button type="text" icon="el-icon-edit" @click="handleEdit(scope.scope.row,scope.scope.$index)">修改</el-button>
            </template>
        </basic-table>
        <add ref="sys-add" @table-search="query"/>
    </div>
</template>


<script>
import { tableOption } from '@/const/crud/admin/config'
import * as API from '@/api/admin/config'
import Add from './add.vue'
export default {
    components:{Add},
    data() {
        return {
            tableData: [],
            tableOption: tableOption,
            tableLoading: false,
            tablePage: {
                size: 50,
                current: 1,
                total: 0
            },
            config: {
                configName: ''
            }
        }
    },
    methods: {
        query() {
            this.tableLoading = true
            API.page(Object.assign(this.tablePage, this.config)).then(res => {
                this.tableLoading = false
                if (res.data.code === 0) {
                    res.data.data.records.forEach(item=>{
                        item.configTypeName = item.configType == 'Y'?'系统参数':'用户参数'
                    })
                    this.tableData = res.data.data.records
                    this.tablePage.total = Number.parseInt(res.data.data.total)
                }
            })
        },
        handleEdit(row){
            this.$refs['sys-add'].edit(row)
        },
        addSysConfig(){
            this.$refs['sys-add'].show()
        }

    },
    mounted(){
        this.query()
    }
}
</script>